

import java.util.*;

public class BookDatabank {

	public static List<Book> booksList = new ArrayList<Book>();

	public static void insertBook(String title, String author, String publisher, String theme, double price) {

		Book book = new Book(title, author, publisher, theme, price);

		booksList.add(book);

	}

	public static void listBooks() {

		System.out.println(booksList);

	}

	public static void sortByTitle() {
		Book temp = null;
		boolean altered = true;

		while (altered) {
			altered = false;
			for (int j = 0; j < booksList.size() - 1; j++) {
				if (swap(booksList.get(j).getTitle(), booksList.get(j + 1).getTitle())) {
					temp = booksList.get(j + 1);
					booksList.set(j + 1, booksList.get(j));
					booksList.set(j, temp);
					altered = true;
				}
			}
		}
	}

	private static boolean swap(String string, String string2) {
		return string.compareTo(string2) >= 0;
	}

}
